package com.myzk.example.core;

import com.myzk.example.consts.ResultCodeMsg;
import com.myzk.example.error.BizException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理类
 * @author mayong
 * @date 2020-11-09
 **/
@RestControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 处理所有不可知的异常
     * @param e
     * @return
     */
    @ExceptionHandler(Exception.class)
    public Result handleException(Exception e){
        Result errorResult = ResultUtil.error(ResultCodeMsg.ERROR_CODE, e.getMessage());
        return errorResult;
    }

    /**
     * 处理所有业务异常
     * @return
     */
   /* @ExceptionHandler(BizException.class)
    public Result handleBizException(BizException bizException){
        return ResultUtil.error(ResultCodeMsg.ERROR_CODE,bizException.getMessage());
    }*/
}
